package com.yc.chaoshi.cs_manage.controller;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_manage.mapper.PmsFenlei2Mapper;
import com.yc.chaoshi.entity.PmsFenlei1;
import com.yc.chaoshi.entity.PmsFenlei2;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/pmsFenlei2")
public class PmsFenlei2Controller {

    @Resource
    private PmsFenlei2Mapper fenlei2Mapper;
    @RequestMapping("selectFenlei2")
    public Page selectFenlei2(@RequestParam(defaultValue = "") String bname,
                              @RequestParam(defaultValue = "1") int page){
        Page<PmsFenlei2> ipage = new Page<>(page,10);
        ipage.orders().add(OrderItem.asc("aid"));
        System.out.println(fenlei2Mapper.selectfenlei2(bname, (page - 1) * 10,10));
        ipage.setRecords(fenlei2Mapper.selectfenlei2(bname, (page - 1) * 10,10));
        System.out.println(fenlei2Mapper.selectfenlei2(bname,0,1000).size());
        long total = fenlei2Mapper.selectfenlei2(bname,0,1000).size();
        ipage.setTotal(total);
        return ipage;
    }

    @RequestMapping("deleteFenlei2")
    public int deleteFenlei2(@RequestParam int bid){
        fenlei2Mapper.deletefenlei2(bid);
        return 0;
    }

    @RequestMapping("insertFenlei2")
    public int insertFenlei2(@RequestParam String bname,
                             @RequestParam int aid,
                             @RequestParam int display,
                             @RequestParam String des){
        fenlei2Mapper.insertfenlei2(bname, aid, display, des);
        return 0;
    }

    @RequestMapping("updateFenlei2")
    public int updateFenlei2(@RequestParam String bname,
                             @RequestParam int aid,
                             @RequestParam int display,
                             @RequestParam String des,
                             @RequestParam int bid) {
        fenlei2Mapper.updatefenlei2(bname, aid, display, des, bid);
        return 0;
    }

}

